﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace sdm.exam.domain
{
    public class SemesterCalcManager
    {

        public int CalculateSemester(DateTime StartingYear)
        {
            // The semesters between september to febuary has a length of 5 months.
            int semesterPeriod1 = 5;
            // The semesters between febuary to september has a length of 7 months.
            int semesterPeriod2 = 7;

            int yearsPast = DateTime.Now.Year - StartingYear.Year;
            int monthsPast = DateTime.Now.Month - StartingYear.Month;
            int months = yearsPast * 12 + monthsPast;

            int count = 0;
            int semester = 1;

            for (int past = 1; past < months; past++)
            {
                count++;
                if (semester % 2 != 0 && count == semesterPeriod1 || semester % 2 == 0 && count == semesterPeriod2)
                {
                    semester++;
                    count = 1;
                }
            }
            return semester;
        }
    }
}
